#!/usr/bin/python
# -*- coding: UTF-8 -*-
import matplotlib.pyplot as plot
import numpy as np
plot.style.use("ggplot")

x=np.random.randn(200)
y=0.5*x+np.random.rand(200)

margin_board=0.1
width=0.6
margin_between=0.02
height=0.2


left_s=margin_board
bottom_s=margin_board
height_s=width
width_s=width

left_x=margin_board
bottom_x=width+margin_board+margin_between
height_x=height
width_x=width

left_y=width+margin_board+margin_between
bottom_y=margin_board
height_y=width
width_y=height

plot.figure(1,figsize=(8,8))
rect_s=[left_s,bottom_s,width_s,height_s]
rect_x=[left_x,bottom_x,width_x,height_x]
rect_y=[left_y,bottom_y,width_y,height_y]

axScratter=plot.axes(rect_s)
axHisx=plot.axes(rect_x)
axHisx.set_xticks([])
axHisy=plot.axes(rect_y)
axHisy.set_yticks([])

axScratter.scatter(x,y)
lim=np.max([np.fabs(x).max(),np.fabs(y).max()])





bin_width=0.25
lim=int(lim/bin_width+1)*bin_width
axScratter.set_ylim(-lim,lim)
axScratter.set_xlim(-lim,lim)

bins=np.arange(-lim,lim+bin_width,bin_width)
axHisx.hist(x,bins=bins)
axHisx.set_xlim(axScratter.get_xlim())
axHisy.hist(y,bins=bins,orientation="horizontal")
axHisy.set_ylim(axScratter.get_ylim())


plot.show()




